import { RootState } from '@/store'

// 查询阅卷列表
export const select_exam_list_data = (state: RootState) => {
  return state.subject.exam_list_data
}

// 加载效果
export const select_subject_loading = (state: RootState) => {
  return state.subject.loading
}

// 查询树型结构
export const select_subject_tree = (state: RootState) => {
  return state.subject.subject_tree
}

// 查询树型选择器中高亮的二级题目
export const select_subject_two_active = (state: RootState) => {
  return state.subject.subject_two_active
}

// 查询题目列表
export const select_topic_list = (state: RootState) => {
  return state.subject.topic_list
}

// 查询被选中的题目
export const select_active_topic = (state: RootState) => {
  return state.subject.active_topic
}

// 获取当前试卷中选中题目的id
export const select_current_exam_topic_id = (state: RootState) => {
  return state.subject.current_exam_topic_id
}

// 查询阅卷列表中某用户的答题列表或者题目列表----持久化存储
export const select_exam_topic_list = (state: RootState) => {
  // 如果本地已经持久化存储题目的时候
  if (JSON.parse(localStorage.getItem('topic')!)) {
    return JSON.parse(localStorage.getItem('topic')!)
  }
  return state.subject.exam_topic_list
}

//查询现在选中考题的各种信息----持久化存储
export const select_current_exam_topic_data = (state: RootState) => {
  let local_topic = JSON.parse(localStorage.getItem('topic')!)
  if (local_topic) {
    return local_topic.find((item: any) => {
      return state.subject.current_exam_topic_id === item._id
    })
  }

  return state.subject.exam_topic_list.find(item => {
    return state.subject.current_exam_topic_id === item._id
  })
}

// 查询选中的二级课程
export const select_current_subject_two = (state: RootState) => {
  return state.subject.current_subject_two
}

// 查看当前试卷的分数
export const select_current_exam_score = (state: RootState) => {
  return state.subject.current_exam_score
}
